$(function() {
	var grid = $('#grid')._datagrid({
		checkOnSelect : false,
		selectOnCheck : false,
		url : "pushsms/list.html", 
		onBeforeLoad : function(param) {
			if (!$('#queryForm').form('validate')) {
				return false;
			}
			var queryParams = $('#queryForm')._formToJson();
			for (i in queryParams) {
				param[i] = queryParams[i];
			}
		}
	});
	$('#queryButton').click(function(){
        var params = $('#queryForm')._formToJson();
        $(grid).datagrid('load',params);
    });
});

/*$(function() {
    var grid = $('#grid')._datagrid({
        checkOnSelect:false,
        selectOnCheck:false
    });
    $('#queryButton').click(function(){
        var params = $('#queryForm')._formToJson();
        $(grid).datagrid('load',params);
    });
});*/
var formatter = {
	dealpush_status : function(value, rowData, rowIndex) {
		if(value == 0){
    		return "未推送";
    	}else if(value == 1){
    		return "成功";
    	}else{
    		return "失败";
    	}
	},
	deal_sms_status : function(value, rowData, rowIndex) {
		if(value == 0){
    		return "<a class='spacing a-blue' onclick='dealdetail(" + rowIndex+ ");' href='javascript:void(0);'>未开启("+rowData.deal+"/"+rowData.alls+")</a>";
    	}else if(value == 1){
    		return "<a class='spacing a-blue' onclick='dealdetail(" + rowIndex+ ");' href='javascript:void(0);'>部分完成("+rowData.deal+"/"+rowData.alls+")</a>";
    	}else if(value == 2){
    		return "<a class='spacing a-blue' onclick='dealdetail(" + rowIndex+ ");' href='javascript:void(0);'>全部完成("+rowData.deal+"/"+rowData.alls+")</a>";
    	}else{
    		return "<a class='spacing a-blue' onclick='dealdetail(" + rowIndex+ ");' href='javascript:void(0);'>全部失败("+rowData.deal+"/"+rowData.alls+")</a>";
    	}
    },
    transferpush_status : function(value, rowData, rowIndex) {
		if(value == 0){
    		return "未推送";
    	}else if(value == 1){
    		return "成功";
    	}else{
    		return "失败";
    	}
	},
	transfer_sms_status : function(value, rowData, rowIndex) {
    	if(value == 0){
    		return "<a class='spacing a-blue' onclick='transferdetail(" + rowIndex+ ");' href='javascript:void(0);'>未开启("+rowData.transfer+"/"+rowData.alls+")</a>";
    	}else if(value == 1){
    		return "<a class='spacing a-blue' onclick='transferdetail(" + rowIndex+ ");' href='javascript:void(0);'>部分完成("+rowData.transfer+"/"+rowData.alls+")</a>";
    	}else if(value == 2){
    		return "<a class='spacing a-blue' onclick='transferdetail(" + rowIndex+ ");' href='javascript:void(0);'>全部完成("+rowData.transfer+"/"+rowData.alls+")</a>";
    	}else{
    		return "<a class='spacing a-blue' onclick='transferdetail(" + rowIndex+ ");' href='javascript:void(0);'>全部失败("+rowData.transfer+"/"+rowData.alls+")</a>";
    	}
    }
};

//短信详情
var phoneformatter = {
	status : function(value, rowData, rowIndex) {
    	if(value == 1){
    		return "<font color='#00FF00'>发送成功</font>";
    	}else if(value == 2){
    		return "<font color='#EE0000'>发送失败</font>";
    	}else{
    		return "--";
    	}	
	}
};
$(function() {
	//初始化弹出框
	$('#phoneDetailDialog').dialog({
		buttons:[{text:'关闭',handler:function(){$('#phoneDetailDialog').dialog('close');}}]
    });
	var grid = $('#phoneGrid')._datagrid({
		checkOnSelect : false,
		selectOnCheck : false
	});
});


/* 短信发送情况*/
function dealdetail(rowIndex){
	var data = $('#grid').datagrid('getRows')[rowIndex];
	var url = "pushsms/sms_data.html?orderId="+data.order_no+"&type=1";
	$("#phoneGrid").datagrid({url:url});
	$('#phoneDetailDialog').dialog('open').dialog("setTitle","短信发送情况");
}
function transferdetail(rowIndex){
	var data = $('#grid').datagrid('getRows')[rowIndex];
	var url = "pushsms/sms_data.html?orderId="+data.order_no+"&type=2";
	$("#phoneGrid").datagrid({url:url});
	$('#phoneDetailDialog').dialog('open').dialog("setTitle","短信发送情况");
}

